<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;" name="viewport" />
		<title>确认订单</title>
		<link rel="stylesheet" type="text/css" href="css/main.css" />
		<link rel="stylesheet" type="text/css" href="css/order.css" />
		<script src="js/rem.js" type="text/javascript" charset="utf-8"></script>
	</head>

	<body>
		<div class="main" id="main" v-cloak>
			<div class="list">
				<div class="list_content">
					<div>
						<img :src="return_data.chapter_pic" v-if="GetQueryString('id')" />
						<img :src="return_data.course_pic" v-if="!GetQueryString('id')" />
					</div>
					<div>
						<p v-if="!GetQueryString('id')">{{return_data.course_name}}</p>
						<p v-if="!GetQueryString('id')">￥{{return_data.course_price}}</p>
						<p v-if="GetQueryString('id')">{{return_data.chapter_name}}</p>
						<p v-if="GetQueryString('id')">￥{{return_data.chapter_price}}</p>
					</div>
				</div>
			</div>
			<!--<div class="amount">
				小计：￥{{return_data.course_price}}
			</div>-->
			<div class="bottom">
				<div>
					<span v-if="GetQueryString('course_type') != 7">合计￥{{return_data.course_price}}</span>
					<span v-if="GetQueryString('course_type') == 7">合计￥{{return_data.chapter_price}}</span>
					<span @click="payment()">立即支付</span>
				</div>
			</div>
		</div>
		<script src="js/jweixin-1.4.0.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/jquery-1.9.1.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/common.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/vue.min.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			getOpenId();
			if(GetQueryString("id")) {
				$.ajax({
					url: apiPath + 'course/get-chapter',
					type: 'post',
					dataType: 'json',
					data: {
						open_id: open_id,
						chapter_id: GetQueryString("id"),
						flagsign: 1
					},
					success: function(data) {
						var right = new Vue({
							el: '#main',
							data: {
								return_data: data.returnData,
							},
							methods: {
								payment: function() {
									var order_type = 0;
									if(GetQueryString("course_type") == 7) {
										order_type = 0;
									} else {
										order_type = 1;
									}
									//微信支付
									$.ajax({
										url: apiPath + 'order/submit-order',
										type: 'post',
										dataType: 'json',
										data: {
											open_id: open_id,
											course_id: data.returnData.course_id,
											chapter_id: GetQueryString("id"),
											order_type: order_type,
											flagsign: 1
										},
										success: function(data) {
											function onBridgeReady() {
												console.log(666)
												WeixinJSBridge.invoke(
													'getBrandWCPayRequest', {
														"appId": data.returnData.appId, //公众号名称，由商户传入     
														"timeStamp": data.returnData.timeStamp, //时间戳，自1970年以来的秒数     
														"nonceStr": data.returnData.nonceStr, //随机串     
														"package": data.returnData.package,
														"signType": data.returnData.signType, //微信签名方式：     
														"paySign": data.returnData.paySign //微信签名 
													},
													function(res) {
														if(res.err_msg == "get_brand_wcpay_request:ok") {
															 window.location.href=document.referrer;
														}
													});
											}
											if(typeof WeixinJSBridge == "undefined") {
												if(document.addEventListener) {
													document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
												} else if(document.attachEvent) {
													document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
													document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
												}
											} else {
												onBridgeReady();
											}
										}
									});
								}
							}
						});
					}
				})
			} else {
				//获取课程
				$.ajax({
					url: apiPath + 'course/get-info',
					type: 'post',
					dataType: 'json',
					data: {
						open_id: open_id,
						token: getData('token'),
						course_type: GetQueryString("course_type"),
						extend_type: GetQueryString("extend_type"),
						flagsign: 1
					},
					success: function(data) {
						var right = new Vue({
							el: '#main',
							data: {
								return_data: data.returnData,
							},
							methods: {
								payment: function() {
									var order_type = 0;
									if(GetQueryString("course_type") == 7) {
										order_type = 0;
									} else {
										order_type = 1;
									}
									//微信支付
									$.ajax({
										url: apiPath + 'order/submit-order',
										type: 'post',
										dataType: 'json',
										data: {
											open_id: open_id,
											course_id: data.returnData.course_id,
											chapter_id: "",
											order_type: order_type,
											flagsign: 1
										},
										success: function(data) {
											function onBridgeReady() {
												WeixinJSBridge.invoke(
													'getBrandWCPayRequest', {
														"appId": data.returnData.appId, //公众号名称，由商户传入     
														"timeStamp": data.returnData.timeStamp, //时间戳，自1970年以来的秒数     
														"nonceStr": data.returnData.nonceStr, //随机串     
														"package": data.returnData.package,
														"signType": data.returnData.signType, //微信签名方式：     
														"paySign": data.returnData.paySign //微信签名 
													},
													function(res) {
														if(res.err_msg == "get_brand_wcpay_request:ok") {
															 window.location.href=document.referrer;
														}
													});
											}
											if(typeof WeixinJSBridge == "undefined") {
												if(document.addEventListener) {
													document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
												} else if(document.attachEvent) {
													document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
													document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
												}
											} else {
												onBridgeReady();
											}
										}
									});
								}
							}
						});
					},
				});
			}
		</script>
	</body>

</html>